package com.codeczx.completeuidemo.recyclerview.md;

import android.content.res.Resources;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.codeczx.completeuidemo.recyclerview.library.sticky_headers.StickyHeadersLinearLayoutManager;
import com.codeczx.completeuidemo.recyclerview.md.RV1Contract.RV1Presenter;

import com.codeczx.completeuidemo.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Rv1Activity extends AppCompatActivity implements RV1Contract.RV1View{

    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.collapsing_toolbar)
    CollapsingToolbarLayout collapsingToolbar;
    @BindView(R.id.appbar)
    AppBarLayout appbar;
    @BindView(R.id.rv1)
    RecyclerView rv1;

    private RV1Adapter mAdapter;
    private RV1Presenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rv1_actvity);
        ButterKnife.bind(this);
        mAdapter = new RV1Adapter(mCallback);
        mPresenter = new RV1PresenterImpl(this,this);
        rv1.setAdapter(mAdapter);
        rv1.setLayoutManager(new StickyHeadersLinearLayoutManager<>(this));
        setupToolbar();
        setFullscreenLayout();
    }

    private void setupToolbar(){
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayShowTitleEnabled(false);
        }
    }

    protected void setFullscreenLayout() {
        View decor = getWindow().getDecorView();
        int flags = decor.getSystemUiVisibility();
        flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
        decor.setSystemUiVisibility(flags);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.initData();
    }

    @Override
    public void onDataLoaded(List<Object> items) {
        mAdapter.setItems(items);
    }

    private RV1Adapter.Callback mCallback = new RV1Adapter.Callback() {
        @Override
        public void onType1Click(Object item) {
            Toast.makeText(Rv1Activity.this,item.toString(),Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onType2Click(Object item) {
            Toast.makeText(Rv1Activity.this,item.toString(),Toast.LENGTH_SHORT).show();
        }
    };

}
